package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.AddressBook;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ShoppingCartController
 * @Author lyh
 * @Date 2024-10-07
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户端购物车管理")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * 添加购物车
     * @param dto
     * @return
     */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<String> addCart(@RequestBody ShoppingCartDTO dto){
        shoppingCartService.addCart(dto);
        return Result.success();
    }

    /**
     * 根据当前用户获取购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据当前用户获取购物车")
    public Result<List<ShoppingCart>> getShoppingCartList(){
        List<ShoppingCart> list= shoppingCartService.getShoppingCartListByUserId();
        return Result.success(list);
    }

    /**
     * 根据当前用户清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("根据当前用户清空购物车")
    public Result<String> cleanCartByUserId(){
        shoppingCartService.cleanCartByUserId();
        return Result.success();
    }
}
